import request from '@/utils/request'
import MD5 from 'js-md5';
import qs from 'qs'
import ServerResponseCode from '@/utils/ServerResponseCode';
// 请求地址前缀
const REQUEST_URL_PRE = "/manage/login";
/**
 * 获取验证码图片地址
 */
export const fetchAuthCodeUrl = function () {
    return ServerResponseCode.PROJECT_SERVER_PRE + REQUEST_URL_PRE + "/authCode?_" + new Date().getTime();
}

/**
* 发起登录/注册
* @param {String} email
* @param {String} password
* @param {String} authCode
* @param {boolean} isRegister
* @param {String} account
*/
export const submitLogin = function (email, password, authCode, isRegister, account) {
    let md5Password = MD5(email + password)
    let data = {
        "email": email,
        "password": md5Password, 
        "authCode": authCode,
        "isRegister": isRegister,
        "account": account,
    }
    let requestData = qs.stringify(data);
    return request({
        url: REQUEST_URL_PRE + '/submit',
        method: 'post',
        data: requestData
    })
}

/**
* 发起APP中的登录
* @param {String} email
* @param {String} password
* @param {String} zfbAccount
*/
export const submitAppLogin = function (email, password, zfbAccount) {
    let md5Password = MD5(email + password)
    let data = {
        "email": email,
        "password": md5Password,
        "zfbAccount": zfbAccount
    }
    let requestData = qs.stringify(data);
    return request({
        url: REQUEST_URL_PRE + '/app/submit',
        method: 'post',
        data: requestData
    })
}


/**
 * 发送重置密码邮件
 * @param {String} email 
 */
export const sendInitPasswordMail = function (email) {
    let data = { "email": email };
    return request({
        url: REQUEST_URL_PRE + '/sendInitPasswordMail',
        method: 'get',
        params: data
    })
}
